Testing and Debugging
Tags: #◇Conceptual #◇CCPROG1 #◇Debugging #◇Software Quality #◇M7
◇Overview
Testing is the process of evaluating a program to verify that it functions exactly as intended, while debugging is the process of finding and fixing the defects (bugs) discovered during testing or execution.
◇Key Definitions
Bug: An error, flaw, or fault in a computer program that produces an incorrect or unexpected result. Syntax Error: Mistakes in the source code grammar that prevent the code from compiling. Logic Error: The program runs but produces incorrect outputs because the underlying algorithm is flawed. Runtime Error: Errors that occur during the execution of a program (e.g., dividing by zero). Test Cases: Specific sets of inputs and expected outputs used to test a program.
◇Theoretical Framework
The Debugging Process
- Identify the Error: Notice that the program is not behaving as expected.
- Analyze the Cause: Understand why the error is occurring.
- Fix the Bug: Modify the code to resolve the issue.
- Re-test: Verify that the fix worked and did not introduce new bugs.
Testing Strategies Black-box Testing: Testing functionality without looking at the internal code structure. Focuses purely on inputs and expected outputs. White-box Testing: Testing internal structures, logic paths, and edge cases by reading the source code. Boundary/Edge Cases: Testing values at the extremes of allowed inputs (e.g., an empty string, 0, negative numbers).
[!tip] Best Practice
When debugging in C, a simple but effective technique is addingprintf()statements at key points to track variable values and control flow. For complex issues, use a debugger likegdbto step through the code line by line.
◇Common Pitfalls
Changing code randomly in hopes of fixing a bug ("shotgun debugging") instead of tracing the logic. Testing only the "happy path" (normal inputs) and ignoring edge cases. Failing to properly read compiler error messages, which often point directly to the source of syntax errors.
◇References & Navigation
- Previous Topic: ◇Iterative Statements in C
- Next Topic: ◇Coding Standards
- Related Notes: ◇Debugging and Test Tools, ◇Exception Handling
ACTIVE RECALL VERIFICATION
Select an answer to verify conceptual comprehension and reveal the technical rationale.
Which type of error occurs when a C program compiles without warnings or errors, runs to completion, but produces an incorrect calculation result (such as using + instead of *)?
When designing test cases for a function that accepts a student score in the valid range [0, 100], which set of inputs best represents Boundary Value Analysis?
What is the difference between Black-Box Testing and White-Box Testing?
Which of the following causes a Linker Error rather than a Compile-Time Syntax Error in C?
What is a "driver" in the context of unit testing modular C programs?